﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevComponents.DotNetBar;
using System.Windows.Forms;
using System.Data;
using BUS;
using DTO;
namespace QuanLyKeHoach
{
    class DieuKhien
    {

        string[] arrtentab = new string[20];
        Boolean tontai = false;
        int[] index = new int[20];
        int tabthu = 0;
        int arrlength = 0;

        public List<ArrList> list;
        public void hienTap(Form frm, Button bnt, DevComponents.DotNetBar.TabControl tap)
        {

        }
        private ArrList layArr(ButtonItem bnt, List<ArrList> lis)
        {
            int dem = list.Count - 1;
            for (int i = 0; i < dem; i++)
            {
                if ((bnt.Text == lis[i].btn.Text))
                {
                    return list[i];
                }
            }
            return null;
        }
        private kiemTra
        public void hientab(Form from, string tentab, DevComponents.DotNetBar.TabControl tab)
        {
            for (int i = 0; i < arrtentab.Length; i++)
            {
                if (arrtentab[i] == tentab.Trim()) { tontai = true; tab.SelectedTabIndex = i; break; }
                else tontai = false;
            }
            if (tontai == false) { newtap(from, tentab, tab, tab.Tabs.Count); tontai = false; }
        }
        public void XoaTap(DevComponents.DotNetBar.TabControl tab)
        {
            TabItem itemToRemove = tab.SelectedTab;
            tab.Tabs.Remove(itemToRemove);
            int xoatab = Convert.ToInt32(tab.SelectedTabIndex);
            //MessageBox.Show(xoatab + "   " + (tab.Tabs.Count - 1));
            if (xoatab == tab.Tabs.Count - 1)
            {
                arrtentab[xoatab + 1] = null;
            }
            else
            {
                for (int i = xoatab; i < arrtentab.Length; i++)
                {
                    arrtentab[i] = arrtentab[i + 1];
                    if (i == tab.Tabs.Count) { arrtentab[i] = null; break; }
                }
            }
        }
        void newtap(Form from, string tentab, DevComponents.DotNetBar.TabControl tab, int vitri)
        {
            arrlength++;
            TabItem newTab = tab.CreateTab(tentab.Trim());
            tab.Text = tentab.Trim();
            tab.Name = "tap" + tabthu;
            TabControlPanel panel = (TabControlPanel)newTab.AttachedControl;
            from.TopLevel = false;
            from.Dock = DockStyle.Fill;
            from.Visible = true;
            panel.Controls.Add(from);
            tab.SelectedTabIndex = tab.Tabs.Count - 1;
            arrtentab[vitri] = tab.Text;
            tabthu++;
        }
        public void thongbao(string text)
        {
            MessageBoxEx.EnableGlass = false;
            MessageBoxEx.Show("<font color='#4B6C9E' size='13' >" + text + "</font>", "<font color='#0000cc' size='12' >Thông Báo</font>", MessageBoxButtons.OK);
        }
        public string load_ma(string strDau, DataTable dt)
        {
            string chuoi = dt.Rows[dt.Rows.Count - 1][0].ToString();
            string[] chuoi_tach = chuoi.Split(new Char[] { '_' });
            return (strDau + "_0" + (Convert.ToInt16(chuoi_tach[1]) + 1));
        }

    }

}
